﻿using MongoDB.Driver;

namespace MongoDb.Api.Repository
{

    /// <summary>
    /// MongoDB仓储接口类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IBaseRepository<T> where T : class
    {

        void Create(T T);
        void CreateList(List<T> Ts);

        IEnumerable<T> GetTs();
        T GetTById(string id);
        IEnumerable<T> GetTsByPage(int Page, int PageSize);
        IEnumerable<T> GetTsBySort(T T, int page, int pageSize, string sortField);
        
        /// <summary>
        /// 单项更新
        /// </summary>
        /// <param name="id"></param>
        /// <param name="T"></param>
        void Update(string id, T T);
        /// <summary>
        /// 批量更新
        /// </summary>
        /// <param name="id"></param>
        /// <param name="T"></param>
        void UpdateList(Dictionary<string, T> updates);
        /// <summary>
        /// 单项删除
        /// </summary>
        /// <param name="T"></param>
        void Delete(string id);
        /// <summary>
        /// 删除操作
        /// </summary>
        /// <param name="T"></param>
        void DeleteList(List<string> filterIds);
        /// <summary>
        /// 数据是否存在
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        bool TExists(string id);
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="id"></param>
        /// <param name="T"></param>
        void Replace(string id, T T);
        /// <summary>
        /// 创建索引
        /// </summary>
        /// <returns></returns>
        CreateIndexModel<T> CreateIndex(IndexKeysDefinition<T> indexKeys, CreateIndexOptions indexOptions = null);
    }
}
